import execjs
# print(execjs.get().name)


fun = """
function exefunc(){
    console.log("hello execjs");
    return "Jackson is a good man";
}
"""
# context = execjs.eval(fun)
# print(context)

#读取js文件

#请利用execjs模块执行   fun之后的代码
result = execjs.compile(fun).call('exefunc')
print(result)

func1 = """
function add(a,b){
    return a + b;
}
"""

ctx = execjs.compile(func1).call('add',18,18)
print(ctx)

context = execjs.compile(func1)

result = context.eval("add(2,5)")
print(result)

exit()

with open("测试js.js",'r',encoding='utf-8') as f:
    json_data = f.read()

compile = execjs.compile(json_data)
res = compile.call('man')
print(res)
res = compile.call('add',1,2)
print(res)
